package com.samoiloff.util.nav {

	/**
	 * @author NM Group
	 */
	public class DirectionData {
		
		private var _x:int;
		private var _y:int;
		
		public function DirectionData() {
			
		}
		
		public function setData(x:int, y:int):void {
			_x = x;
			_y = y;
		}
		
		public function move(dir:int, distance:int = 1):void {
			
			switch (dir) {
				case GameDirection.RIGHT		: _x = _x + distance; break; 
				case GameDirection.BOTTOM_RIGHT	: _x = _x + distance; _y = _y + distance; break; 
				case GameDirection.BOTTOM		: _y = y + distance; break; 
				case GameDirection.BOTTOM_LEFT	: _x = x - distance; _y = y + distance; break; 
				case GameDirection.LEFT			: _x = x - distance; break; 
				case GameDirection.TOP_LEFT		: _x = x - distance; _y =y - distance; break; 
				case GameDirection.TOP			: _y = y - distance; break; 
				case GameDirection.TOP_RIGHT	: _x = x + distance; _y = y - distance; break; 
				default:
					throw new Error("Direction is out of range : " + dir);
				break;
			}
		}
		
		public function getDirByAngle(gradusAngle:Number):int {
			while (gradusAngle < 0) { gradusAngle += 360; } 
			while (gradusAngle >= 360) { gradusAngle -= 360; }
			
			var dir:int = Math.floor((gradusAngle + 22.5)/45);
			return dir % 8;
		}

		public function get x() : int {
			return _x;
		}

		public function get y() : int {
			return _y;
		}
	}
}
